/**
 * Created by jiangtao on 2017/5/27.
 */

import types from './../const/home';

export default {
    getList( params ){
        return ( sync ) => {
           loading();
           ajax.get({
               url:"/topics",
               data:params
           }).then(( res )=> {
               if(!res.success) return;
               let dataList = res.data;
               sync({type:types.GET_LIST , data :dataList });
               document.body.scrollTop = 0;
           }).fail(()=>{

           }).always( () =>{
               loadingClose();
           })
       }
    },
    getDetail( id , success=()=>{}){
        loading();
         return ( sync ) => {
             ajax.get({
                 url:"/topic/"+id,
             }).then(( res )=> {
                 if(!res.success) return;
                 let detail = res.data;
                 sync({type:types.GET_DETAIL , data :detail });
             }).fail(()=>{

             }).always( () =>{
                 success();
                 loadingClose();
             })
         }
    },
    changeTab( index ){
        return { type : types.CHANGE_TAB , data:index}
    }
}